﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Text;
using Frame.Lib.Core.Right;
using Frame.Lib.Utilities;
using Frame.Lib.Enums;
using Frame.Lib.Core.Role;

public partial class Admin_Role_SaveRight : System.Web.UI.Page
{
    private SystemRightBO _right;
    private SystemRightBO Right
    {
        get
        {
            if (_right == null)
            {
                _right = new SystemRightBO(RightOwnerType.Role);
            }
            return _right;
        }
    }
    private int RoleID
    {
        get
        {
            return int.Parse(StrUtil.DecryptUrl(Request["RoleID"]));
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {       
            
            BindView();
            if (RoleID < 0)
            {
                lblName.Text = ((InternalRole)RoleID).ToString();
            }
            else
            {
                lblName.Text = (new RoleBO()).GetName(RoleID);
            }
        }
        SystemRightBO.RegisterRightHiddenField();
    }

    private void BindView()
    {
        DataTable dt = SystemRightBO.GetRightRect();
        StringBuilder sb = new StringBuilder();
        sb.Append("<table class='tbl1'>");
        foreach (DataRow dr in dt.Rows)
        {
            sb.Append("<tr>");
            sb.Append("<td class='head'>" + dr[0] + "：</td>");

            for (int i = 1; i < dt.Columns.Count; i++)
            {
                sb.Append("<td>" + dr[i] + "</td>");
            }
           
            sb.Append("</tr>");
        }
        sb.Append("</table>");

        tbl.Text = sb.ToString();

        List<int> lstSelectIDs = Right.GetRightIDs(RoleID);
        JSUtil.ExcuteJS("InitSelect('" + StrUtil.MergeToStr(lstSelectIDs, ",") + "')");

    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        List<int> lstRightIDs = StrUtil.SplitToInt(Request.Form["hidRightID"]);
       
        Right.SaveRight(RoleID, lstRightIDs);
        string strScript = "window.close();returnValue=true";
        JSUtil.ResponseJS(strScript);
    }
}
